package com.luck.easyfoodbatch.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.mvp.model.PointModel;
import com.luck.easyrecyclerview.adapter.BaseViewHolder;
import com.luck.easyrecyclerview.adapter.RecyclerArrayAdapter;

/**
 * author：luck
 * project：LoveCare
 * package：com.tongyu.luck.lovecare.adapter
 * email：893855882@qq.com
 * data：16/8/12
 */
public class CouponAdapter extends RecyclerArrayAdapter<PointModel.DataBean.ModelsBean> {
    private Context mContext;

    public CouponAdapter(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {

        return new CouponViewHolder(parent);
    }

    public class CouponViewHolder extends BaseViewHolder<PointModel.DataBean.ModelsBean> {
        TextView tv_coupon_type, tv_coupon_money, tv_coupon_http, tv_coupon_flag, tv_time_line;
        ImageView iv_cb;
        LinearLayout ll_coupon_bg,ll_left_coupon_bg;

        public CouponViewHolder(ViewGroup parent) {
            super(parent, R.layout.coupon_chang_item);
            tv_coupon_type = $(R.id.tv_coupon_type);
            tv_coupon_money = $(R.id.tv_coupon_money);
            tv_coupon_http = $(R.id.tv_coupon_http);
            tv_coupon_flag = $(R.id.tv_coupon_flag);
            tv_time_line = $(R.id.tv_time_line);
            iv_cb = $(R.id.iv_cb);
            ll_coupon_bg = $(R.id.ll_coupon_bg);        //底部背景
            ll_left_coupon_bg = $(R.id.ll_left_coupon_bg);//左边背景 S
        }

        @Override
        public void setData(final PointModel.DataBean.ModelsBean bean, int position) {
            if (bean.isChecked()) {
                iv_cb.setImageResource(R.mipmap.select_sel_1x);
            } else {
                iv_cb.setImageResource(R.mipmap.select_def_1x);
            }
            int type = bean.getType();//1通用2指定店铺3指定商品
            switch (type) {
                case 1:
                    tv_coupon_type.setText("通用类");
                    break;
                case 2:
                    tv_coupon_type.setText("指定店铺");
                    break;
                case 3:
                    tv_coupon_type.setText("指定商品");
                    break;
            }

            int money = (int) bean.getDec_money();
            if (money==5){
                ll_coupon_bg.setBackgroundResource(R.mipmap.coupon5);
                ll_left_coupon_bg.setBackgroundResource(R.mipmap.coupon_s5);
            }else if (money==10){
                ll_coupon_bg.setBackgroundResource(R.mipmap.coupon10);
                ll_left_coupon_bg.setBackgroundResource(R.mipmap.coupon_s10);
            }else if (money==20){
                ll_coupon_bg.setBackgroundResource(R.mipmap.coupon20);
                ll_left_coupon_bg.setBackgroundResource(R.mipmap.coupon_s20);
            }else if (money==30){
                ll_coupon_bg.setBackgroundResource(R.mipmap.coupon30);
                ll_left_coupon_bg.setBackgroundResource(R.mipmap.coupon_s30);
            }else if (money==50){
                ll_coupon_bg.setBackgroundResource(R.mipmap.coupon50);
                ll_left_coupon_bg.setBackgroundResource(R.mipmap.coupon_s50);
            }else if (money==100){
                ll_coupon_bg.setBackgroundResource(R.mipmap.coupon100);
                ll_left_coupon_bg.setBackgroundResource(R.mipmap.coupon_s100);
            }else if (money==200){
                ll_coupon_bg.setBackgroundResource(R.mipmap.coupon200);
                ll_left_coupon_bg.setBackgroundResource(R.mipmap.coupon_s200);
            }else{
                ll_coupon_bg.setBackgroundResource(R.mipmap.coupon);
                ll_left_coupon_bg.setBackgroundResource(R.mipmap.coupons);
            }

            tv_coupon_flag.setText("满" + bean.getFull_money() + "减" + bean.getDec_money() + "元");
            tv_time_line.setText("有效期：" + bean.getEffective_day() + "天");
            tv_coupon_money.setText(money + "");
            tv_coupon_http.setText(bean.getTitle());
        }
    }
}
